bitkeeper revision 1.1159.172.3 (4194d17cHAKS_aZt34dj741AVg4MNQ)
authorcl349@freefall.cl.cam.ac.uk <cl349@freefall.cl.cam.ac.uk>
Fri, 12 Nov 2004 15:06:36 +0000 (15:06 +0000)
committercl349@freefall.cl.cam.ac.uk <cl349@freefall.cl.cam.ac.uk>
Fri, 12 Nov 2004 15:06:36 +0000 (15:06 +0000)
Split irq_serial_getc out of serial_getc, irq_serial_getc can be called from
interrupt handlers.

xen/drivers/char/console.c
xen/drivers/char/serial.c
xen/include/xen/console.h
xen/include/xen/serial.h

index 7a706b2e2c1eda2e63298a77789ece95025f1fa9..cb577409969c7e063f5c754e749e51b9e121b5b8 100644 (file)
@@ -436,6 +436,21 @@ void console_force_lock(void)
     spin_lock(&console_lock);
 }
 
+void console_putc(char c)
+{
+    serial_putc(sercon_handle, c);
+}
+
+int console_getc(void)
+{
+    return serial_getc(sercon_handle);
+}
+
+int irq_console_getc(void)
+{
+    return irq_serial_getc(sercon_handle);
+}
+
 
 /*
  * **************************************************************
index 8ca8972175633c9a913cefaa48294b16cce94480..bdd1995f52ca8f3dbb4a60e1e00238971257d42b 100644 (file)
@@ -416,13 +416,10 @@ static int byte_matches(int handle, unsigned char *pc)
     return 0;
 }
 
-unsigned char serial_getc(int handle)
+unsigned char irq_serial_getc(int handle)
 {
     uart_t *uart = &com[handle & SERHND_IDX];
     unsigned char c;
-    unsigned long flags;
-
-    spin_lock_irqsave(&uart->lock, flags);
 
     while ( uart->rxbufp != uart->rxbufc )
     {
@@ -431,16 +428,6 @@ unsigned char serial_getc(int handle)
             goto out;
     }
     
-    disable_irq(uart->irq);
-    
-    /* disable_irq() may have raced execution of uart_rx(). */
-    while ( uart->rxbufp != uart->rxbufc )
-    {
-        c = uart->rxbuf[MASK_RXBUF_IDX(uart->rxbufc++)];
-        if ( byte_matches(handle, &c) )
-            goto enable_and_out;
-    }
-
     /* We now wait for the UART to receive a suitable character. */
     do {
         while ( (inb(uart->io_base + LSR) & LSR_DR) == 0 )
@@ -449,7 +436,29 @@ unsigned char serial_getc(int handle)
     }
     while ( !byte_matches(handle, &c) );
     
- enable_and_out:
+ out:
+    return c;
+}
+
+unsigned char serial_getc(int handle)
+{
+    uart_t *uart = &com[handle & SERHND_IDX];
+    unsigned char c;
+    unsigned long flags;
+
+    spin_lock_irqsave(&uart->lock, flags);
+
+    while ( uart->rxbufp != uart->rxbufc )
+    {
+        c = uart->rxbuf[MASK_RXBUF_IDX(uart->rxbufc++)];
+        if ( byte_matches(handle, &c) )
+            goto out;
+    }
+    
+    disable_irq(uart->irq);
+
+    c = irq_serial_getc(handle);
+    
     enable_irq(uart->irq);
  out:
     spin_unlock_irqrestore(&uart->lock, flags);
index 628eb044d45cfaa980e4254f6f3250db8013568f..abcb2fa1d8ef371b0ffec61dbf1e18e42f776262 100644 (file)
@@ -22,4 +22,8 @@ void console_endboot(int disable_vga);
 void console_force_unlock(void);
 void console_force_lock(void);
 
+void console_putc(char c);
+int console_getc(void);
+int irq_console_getc(void);
+
 #endif
index c0ffebbbd9c2d1f98f10cd8a38dc7750a8c740ed..b805405093bc1a3cfd138ba55d431866b42e7410 100644 (file)
@@ -41,6 +41,7 @@ void serial_puts(int handle, const unsigned char *s);
  * will not return until a character is available. It can safely be
  * called with interrupts disabled.
  */
+unsigned char irq_serial_getc(int handle);
 unsigned char serial_getc(int handle);
 
 void serial_force_unlock(int handle);